/*
 * Licensed to the http://code.google.com/p/crunchutils under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.crunchutils;

import java.io.File;
import static org.crunchutils.CrunchZipUtils.*;

/**
 * This class exposes much of the functionalities provided by crunchutils via the main method
 * which can be executed from a command line
 * @author James Selvakumar
 */
public class CrunchUtils
{
    public static void main(String[] args)
    {
        if (args != null && args.length >= 1) {
            if (args[0].equalsIgnoreCase("help")) {
                printHelp();
            }
            if (args[0].equalsIgnoreCase("zip")) {
                zip(args);
            } else {
                unSupportedOperation();
            }
        } else {
            invalidUsage();
        }
    }

    private static void zip(String[] args)
    {
        if (args.length == 2) {
            System.out.println("Zipping and deleting the file " + args[1]);
            zipAndDelete(new File(args[1]));
        } else if (args.length == 3) {
            System.out.println("Zipping and deleting the file " + args[1] + ", output file is " + args[2]);
            zipAndDelete(new File(args[1]), new File(args[2]));
        } else {
            invalidUsage();
        }
    }

    private static void unSupportedOperation()
    {
        System.out.println("Unsupported operation");
    }

    private static void invalidUsage()
    {
        System.out.println("Invalid number of arguments!");
        printHelp();
    }

    private static void printHelp()
    {
        System.out.println("Usage:");
        System.out.println("java -jar crunchutils*.jar [operation] [arguments..]");
        System.out.println("Examples:");
        System.out.println("java -jar crunchutils*.jar zip /home/file.txt");
        System.out.println("java -jar crunchutils*.jar zip /home/file.txt /home/some-dir/output.zip");
    }
}
